package com.example.boxuegu;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class setting extends AppCompatActivity{

    public static setting instance=null;
    private TextView tv_main_title;
    private TextView tv_back;
    private RelativeLayout rl_title_bar;
    private RelativeLayout rl_modify_paw;
    private RelativeLayout rl_security_setting;
    private RelativeLayout rl_exit_login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        instance =this;
        init();
    }
    /*
    * 获取界面控件*/
    private void init() {
        tv_main_title = (TextView) findViewById(R.id.tv_main_title);
        tv_main_title.setText("设置");
        tv_back =(TextView) findViewById(R.id.tv_back);
        rl_title_bar = (RelativeLayout) findViewById(R.id.title_bar);
        rl_title_bar.setBackgroundColor(Color.parseColor("#30B4FF"));
        rl_modify_paw = (RelativeLayout) findViewById(R.id.rl_modify_psw);
        rl_security_setting = (RelativeLayout) findViewById(R.id.rl_security_setting);
        rl_exit_login = (RelativeLayout) findViewById(R.id.rl_exit_login);
        tv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setting.this.finish();
            }
        });
        //修改密码的点击事件
        rl_modify_paw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到修改密码的界面
                Intent intent = new Intent(setting.this, modify_xml.class);
                startActivity(intent);
            }
        });
        //设置密保得点击事件
        rl_security_setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到设置密保得界面
                Intent intent = new Intent(setting.this, find_psw.class);
                intent.putExtra("from","security");
                startActivity(intent);
            }
        });
        //退出登录的点击事件
        rl_exit_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(setting.this, "退出登陆成功", Toast.LENGTH_SHORT).show();
                clearLoginStatus();//清除登陆状态和登陆时的用户名
                Intent intent = new Intent();//退出后把退出成功的状态传递到MainActivity中去
                intent.putExtra("isLogin",false);
                setResult(RESULT_OK,intent);
                setting.this.finish();
            }
        });
    }

    private void clearLoginStatus() {
        SharedPreferences loginInfo = getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = loginInfo.edit();//获取编译器
        edit.putBoolean("isLogin",false);//清除登陆状态
        edit.putString("loginUserName","");
        edit.commit();
    }


}